package top.tagao.m01_structuralPatterns.s_02_adapter;

import top.tagao.m01_structuralPatterns.s_02_adapter.adapters.SquarePegAdapter;
import top.tagao.m01_structuralPatterns.s_02_adapter.round.RoundHole;
import top.tagao.m01_structuralPatterns.s_02_adapter.round.RoundPeg;
import top.tagao.m01_structuralPatterns.s_02_adapter.square.SquarePeg;

/**
 * @author fu-xiao-liu
 * @Date 2022/7/25 23:27
 */
public class Main {
    public static void main(String[] args) {
        //1.生成圆孔对象
        RoundHole hole = new RoundHole(5);
        RoundPeg rpeg = new RoundPeg(5);
        if (hole.fits(rpeg)) {
            System.out.println("Round peg r5 fits round hole r5.");
        }

        //2.生成适配对象
        SquarePeg smallSqPeg = new SquarePeg(2);
        SquarePeg largeSqPeg = new SquarePeg(20);


        // Adapter solves the problem.
        //3.生成适配器，通过适配对象
        SquarePegAdapter smallSqPegAdapter = new SquarePegAdapter(smallSqPeg);
        SquarePegAdapter largeSqPegAdapter = new SquarePegAdapter(largeSqPeg);
        if (hole.fits(smallSqPegAdapter)) {
            System.out.println("Square peg w2 fits round hole r5.");
        }
        if (!hole.fits(largeSqPegAdapter)) {
            System.out.println("Square peg w20 does not fit into round hole r5.");
        }
    }
}
